package com.example.vueblog.controller;

import cn.hutool.core.date.DateUnit;
import com.example.vueblog.common.utils.ExcelUtils;
import com.example.vueblog.entity.Logs;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.SimpleFormatter;

/**
 * 测试类
 *
 * @author yushunshun
 * @date 2022/7/27 22:46
 */
@RestController
@RequestMapping("test")
public class TestController {

    @GetMapping("/excel/export")
    public void excel_export(HttpServletResponse response) {
        List<Logs> arrayList = new ArrayList<>();
        for (int i = 0; i < 30000; i++) {
            Logs logs = new Logs();
            logs.setOperId(i);
            logs.setTitle("日志名称");
            logs.setOperName("操作名称" + i);
            logs.setOperUrl("abc");
            logs.setStatus(1);
            logs.setOperTime(LocalDateTime.now());
            arrayList.add(logs);
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String excelName = String.format("测试excel名%s.xlsx",format.format(new Date()));
        ExcelUtils.beanExportExcelToResponse(response, excelName, arrayList);
    }
}
